package com.hdu.dwh.dtos.cdc_dtos;

import com.hdu.dwh.utils.CDCUtils;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;

@Data
@EqualsAndHashCode(callSuper = true)
public class PostgresqlcdcDtos extends FlinkJobDto {

    public PostgresqlcdcDtos(){}

    public PostgresqlcdcDtos(String address, Integer port, String username, String password, String sourceDatabaseName, String sourceTableName, String targetDatabaseName, String targetTableName) {
        this.address = address;
        this.port = port;
        this.username = username;
        this.password = password;
        this.sourceDatabase = sourceDatabaseName;
        this.sourceTable = sourceTableName;
        this.targetDatabase = targetDatabaseName;
        this.targetTable = targetTableName;
    }

    @Schema(hidden = true)
    private String entryClass = "org.apache.paimon.flink.action.FlinkActions";

    @Schema(description = "postgresql地址", defaultValue = "127.0.0.1:5432")
    private String address;

    @Schema(description = "postgresql端口", defaultValue = "5432")
    private Integer port;

    @Schema(description = "postgresql用户名", defaultValue = "root")
    private String username;

    @Schema(description = "postgresql密码", defaultValue = "datawarehouse")
    private String password;

    @Schema(description = "postgresql数据库名", defaultValue = "datawarehouse")
    private String sourceDatabase;

    @Schema(description = "postgresql表名", defaultValue = "dates")
    private String sourceTable;

    @Schema(description = "paimon数据库名", defaultValue = "ssb")
    private String targetDatabase;

    @Schema(description = "paimon表名", defaultValue = "dates")
    private String targetTable;

    @Schema(hidden = true)
    public List<String> getPostgresqlCDCConfigList() {
        if (this.address == null || this.port == null || this.username == null || this.password == null || this.sourceDatabase == null || this.sourceTable == null) {
            throw new IllegalArgumentException("参数不能为空" + this.toString());
        }
        List<String> config = CDCUtils.buildPostgresqlCDCParamList(address, port, username, password, targetDatabase, sourceDatabase, targetTable, sourceTable);
        return config;
    }
}
